package com.itheima.sh.o_extends;


import java.util.Arrays;
import java.util.Random;

public class Demo1 {
    public static void main(String[] args) {
        //定义动态数组，长度为10
        int[] arr = new int[10];
        //采用随机数给数组赋值
        Random r = new Random();
        //遍历数组完成随机数赋值
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(100) + 1;
        }
        //定义最大值与最小值
        int max = arr[0];
        int min = arr[0];
        //遍历数组求出最大值和最小值
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
            if (arr[i] < min) {
                min = arr[i];
            }
        }
        System.out.println(Arrays.toString(arr));
        System.out.println("最大值是" + max);
        System.out.println("最小值是" + min);

        //定义第二大和第二小值
        int secondMax=min;
        int secondMin=max;
        //遍历数组
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]>secondMax&&arr[i]<max){
                secondMax=arr[i];
            }
            if (arr[i]<secondMin&&arr[i]>min){
                secondMin=arr[i];
            }
        }
        System.out.println(Arrays.toString(arr));
        System.out.println("第二大值是"+secondMax);
        System.out.println("第二小值是"+secondMin);

    }

}


